package com.cn.qtms.entity;//类注释设置模板

import com.cn.qtms.base.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Name:TmSysUser
 * @Description:
 * @Author: zhangyang
 * @Date: 2019-11-11 12:04
 **/
@Entity
@Table(name = "tm_sys_user")
@org.hibernate.annotations.Table(appliesTo = "tm_sys_user",comment="用户信息表")
@Getter
@Setter
public class TmSysUser extends BaseEntity {

    @Column(name = "username", columnDefinition = "varchar(50) COMMENT '用户名'", unique = true, nullable = false)
    private String username;

    @Column(name = "password", columnDefinition = "varchar(255) COMMENT '密码'", nullable = false)
    private String password;

    @Column(name = "real_name", columnDefinition = "varchar(50) COMMENT '中文名'")
    private String realName;

    @Column(name = "phone", length = 20, unique = true)
    private String phone;

    @Column(name = "user_type", columnDefinition = "char(1) default 1 COMMENT '用户类型0.总部用户 1.供应商用户2.商户用户'")
    private  String userType;

    @Column(name = "email", length = 50, unique = true)
    private String email;

    @Column(name = "dept_id", columnDefinition = "bigint(20) COMMENT '部门id'")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long deptId;

    @Column(name = "step", columnDefinition = "int(10) COMMENT '完成步骤(注册可能分多部,完成每一步进行记录)'")
    private  Integer step;

    @Column(name = "create_time", columnDefinition="datetime COMMENT '创建完成时间'")
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy/MM/dd HH:mm:ss")
    private Date createTime;

    @Column(name="supplier_id", columnDefinition = "bigint(20) COMMENT '供应商id,关联供应商数据库供应商表主键'")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long supplierId;

    @Column(name="client_id", columnDefinition = "bigint(20) COMMENT '商户id，关联商户数据库商户表主键'")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long clientId;

    @Column(name = "status", columnDefinition = "char(1) default '0' COMMENT '用户状态:0激活,1未激活'")
    private String status;

    @Column(name = "is_locked", columnDefinition = "bit(1) default 0  COMMENT '是否锁定'")
    private Boolean isLocked =false;

    @ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY)
    @JoinTable(name = "tr_user_role",
            joinColumns = {@JoinColumn(name = "user_id",
                    referencedColumnName = "id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id",
                    referencedColumnName = "id")})
    private Set<TmSysRole> tmSysRoles;

    /**
     * 前端使用 前端存储的角色编码
     */
    @Transient
    private List<String> roles=new ArrayList<>();

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        return super.equals(obj);
    }
}
